package com.hlt.controller.user;

import com.hlt.dto.LikesDTO;
import com.hlt.dto.LikesPageQueryDTO;
import com.hlt.dto.PostLikesPageQueryDTO;
import com.hlt.result.PageResult;
import com.hlt.result.Result;
import com.hlt.service.ILikesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author lzf
 * @since 2024-11-25
 */
@RestController
@RequestMapping("/users/likes")
@Api(tags = "点赞接口")
@Slf4j
public class LikesController {

    @Autowired
    private ILikesService likesService;

    @PostMapping
    @ApiOperation("点赞文章")
    public Result<String> addLike(@RequestBody LikesDTO likesDTO) {
        log.info("点赞文章：{}", likesDTO.getPostId());
        likesService.addLike(likesDTO);
        return Result.success();
    }

    @DeleteMapping("/{postId}")
    @ApiOperation("取消点赞")
    public Result<String> removeLike(@PathVariable Integer postId) {
        log.info("取消点赞：{}", postId);
        likesService.removeLike(postId);
        return Result.success();
    }

    @GetMapping("/user")
    @ApiOperation("获取用户的点赞列表")
    public Result<PageResult> getUserLikes(LikesPageQueryDTO pageQueryDTO) {
        log.info("获取用户的点赞列表");
        PageResult pageResult = likesService.getUserLikes(pageQueryDTO);
        return Result.success(pageResult);
    }

    @GetMapping("/post")
    @ApiOperation("获取文章的点赞列表")
    public Result<PageResult> getPostLikes(PostLikesPageQueryDTO pageQueryDTO) {
        log.info("获取文章的点赞列表：{}", pageQueryDTO.getPostId());
        PageResult pageResult = likesService.getPostLikes(pageQueryDTO);
        return Result.success(pageResult);
    }
}
